﻿<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Define a lamda Attached RoutedEvent</Title>
            <Shortcut>propeventas</Shortcut>
            <Description>Code snippet for a event using RoutedEvent as the backing store</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>Event Type</ToolTip>
                    <Default>RoutedPropertyChangedEventHandler</Default>
                </Literal>
				<Literal>
                    <ID>T</ID>
                    <ToolTip>Param Type</ToolTip>
                    <Default>object</Default>
                </Literal>
                <Literal>
                    <ID>eventname</ID>
                    <ToolTip>Event Name</ToolTip>
                    <Default>MyEvent</Default>
                </Literal>
                <Literal>
                    <ID>ownerclass</ID>
                    <ToolTip>The owning class of this Property.  Typically the class that it is declared in.</ToolTip>
                    <Default>ownerclass</Default>
                </Literal>
                <Literal>
                    <ID>eventarg</ID>
                    <ToolTip>The default value for this property.</ToolTip>
                    <Default>RoutedPropertyChangedEventArgs</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[
				
public static void Add$eventname$Handler(DependencyObject d, $type$<$T$> handler)
	=>(d as UIElement)?.AddHandler($eventname$Event, handler);
public static void Remove$eventname$Handler(DependencyObject d, $type$<$T$> handler)
	=> (d as UIElement)?.RemoveHandler($eventname$Event, handler);
public static readonly RoutedEvent $eventname$Event =
	EventManager.RegisterRoutedEvent("$eventname$", RoutingStrategy.Bubble, typeof($type$<$T$>), typeof($ownerclass$));
	
private static void On$eventname$(object sender, object oldValue, object newValue)
{
	var element = sender as UIElement;
	$eventarg$<$T$> arg = new $eventarg$<$T$>(oldValue, newValue, $eventname$Event);
	element?.RaiseEvent(arg);
}

$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
